﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace QLCF.Forms.Reports
{
    public partial class frmViewBillDetailsRpt : Form
    {
        public frmViewBillDetailsRpt()
        {
            InitializeComponent();
        }
        private int billID=-1;
        private bool isPrint = false;
        public frmViewBillDetailsRpt(int m_billID, bool m_isPrint)
        {
            InitializeComponent();
            billID=m_billID;
            isPrint = m_isPrint;
        }

        private void frmViewBillDetailsRpt_Load(object sender, EventArgs e)
        {
            reportViewer1.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout);            
            reportViewer1.LocalReport.ReportEmbeddedResource = "QLCF.Reports.rptBill.rdlc";
            WorkFlowBLL.CtrProduct ctrp=new WorkFlowBLL.CtrProduct();
            
            var ContactList=ctrp.BillDetailsGetByBillID(billID);
            var info=ctrp.BillGetInfoCommon(billID);
            WorkFlowBLL.CtrAdmin ctra = new WorkFlowBLL.CtrAdmin();
            var officeInfo = ctra.GetConfig();
            reportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WinForms.ReportParameter("prmNameOffice", officeInfo.OfficeName));
            reportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WinForms.ReportParameter("prmAddress", "Địa chỉ: "+officeInfo.Address));
            reportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WinForms.ReportParameter("prmPhone", "Điện thoại: " + officeInfo.Phone));
            reportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WinForms.ReportParameter("prmNotice", officeInfo.NoticeOnBill));

            reportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WinForms.ReportParameter("prmBillID", "No: "+billID));

            reportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WinForms.ReportParameter("prmDate", (info.EndTime??DateTime.Now).ToString("hh:mm - dd/MM/yyyy")));
            reportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WinForms.ReportParameter("prmTableName", info.TableName));
            reportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WinForms.ReportParameter("prmTotalRecord", ContactList.Count.ToString()));
            reportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WinForms.ReportParameter("prmSumMoney", info.SumMoney == 0 ? "0 VNĐ" : info.SumMoney.ToString("0,0") + " VNĐ"));
            reportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WinForms.ReportParameter("prmPriceServices", info.PriceServices == 0 ? "0 VNĐ" : info.PriceServices.ToString("0,0") + " VNĐ"));
            reportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WinForms.ReportParameter("prmPromotionMoney", info.PromotionMoney==0?"0 VNĐ":info.PromotionMoney.ToString("0,0") + " VNĐ"));
            reportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WinForms.ReportParameter("prmTotalMoney", info.TotalMoney==0?"0 VNĐ":info.TotalMoney.ToString("0,0") + " VNĐ"));
            reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("GetBillDetails", ContactList));
            reportViewer1.ZoomMode = Microsoft.Reporting.WinForms.ZoomMode.Percent;
            reportViewer1.ZoomPercent = 100;
            reportViewer1.RefreshReport();
            if (isPrint)
                reportViewer1.RenderingComplete += new Microsoft.Reporting.WinForms.RenderingCompleteEventHandler(reportViewer1_RenderingComplete);
            
        }
        private void reportViewer1_RenderingComplete(object sender, EventArgs e)
        {                                    
            reportViewer1.PrintDialog();
        }
    }    
}
